//
//  KDChildTypeController.m
//  WangJingApp
//
//  Created by 魏强 on 17/10/13.
//  Copyright © 2017年 KDTech. All rights reserved.
//

#import "KDChildTypeController.h"
#import "KDInfoType.h"
#import "KDSearchResultController.h"
@interface KDChildTypeController ()<UITableViewDelegate, UITableViewDataSource>
/**  <#Description#> */
@property (nonatomic, weak) UITableView *tableView;

@end

@implementation KDChildTypeController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BackGroundColor;
    [self setUpTableView];
    // Do any additional setup after loading the view.
}
- (void)setUpTableView{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(10  , 10, self.view.width -20, self.view.height - 64 -10) style:UITableViewStylePlain];
    tableView.tableFooterView = [UIView new];
    tableView.separatorColor = BackGroundColor;
    self.tableView = tableView;
    //    tableView.editing = YES;
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
}
#pragma mark -UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.infoArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId =@"cellName";
    
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
//        cell.accessoryType = UITableViewCellAccessoryCheckmark;
//        cell.selectedBackgroundView = [[UIView alloc]init];
    }
    KDInfoType *source = self.infoArr[indexPath.row];
    cell.textLabel.text = source.info_type_name;
    
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
//    UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
    //    thisCell.accessoryView.hidden = NO;
    KDInfoType *source = self.infoArr[indexPath.row];
    UIViewController *VC ;
    for (UIViewController *vc in self.navigationController.viewControllers) {//找出出显示地区的控制器
        if ([vc isKindOfClass:[KDBaseRegionController class]])
        {
            if ([vc isKindOfClass:[KDSearchResultController class]])
            {
                KDSearchResultController *searchCtrl = (KDSearchResultController *)vc;
                if (searchCtrl.here) {
                    VC = vc;break;
                }
            }else{
                VC = vc;break;
            }
            
        }
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChooseInfoTypeToReportControllerNoty" object:nil userInfo:@{@"infoName":[NSString stringWithFormat:@"%@  %@",self.title,source.info_type_name],@"infoType":source}];
    [self.navigationController popToViewController:VC animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
